package com.sfzy.controller;

import com.github.pagehelper.PageInfo;
import com.sfzy.entity.Fm;
import com.sfzy.service.FmService;
import com.sfzy.service.PsychKnowService;
import com.sfzy.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName FmController
 * @Description TODO
 * @Author niejiacan
 * @Date 2025年08月14日 11:16
 * @Version 1.0
 */
@RestController
@RequestMapping("fm")
public class FmController {
    @Autowired
    private FmService fmService;


    @PostMapping
    public R addFm(@RequestBody Fm fm){
        int i = fmService.addFm(fm);
        if(i==0){
            return R.fail();
        }
        return R.ok();
    }

    @PutMapping
    public R updateFm(@RequestBody Fm fm){
        int i = fmService.updateFm(fm);
        if(i==0){
            return R.fail();
        }
        return R.ok();
    }

    @DeleteMapping("{id}")
    public R deleteFm(@PathVariable("id") int id){
        int i = fmService.deleteFm(id);
        if(i==0){
            return R.fail();
        }
        return R.ok();
    }

    @GetMapping("{id}")
    public R selectFm(@PathVariable("id") int id){
        Fm fm = fmService.selectFm(id);
        return R.ok(fm);
    }

    @GetMapping("pageName")
    public R pageName(Fm fm,
                      @RequestParam(required = false,defaultValue = "1") int pageNum,
                      @RequestParam(required = false,defaultValue = "5") int pageSize){
        PageInfo<Fm> fmPageInfo = fmService.pageName(fm, pageNum, pageSize);
        return R.ok(fmPageInfo);
    }









}
